package com.chilly.other.jdk8.Interface;

import org.junit.Test;

//定义函数式接口
@FunctionalInterface
interface calculable {
    int add(int x, int y);
}

//定义含有静态方法类
class Method {
    public static int add(int x, int y) {
        return x + y;
    }
}


/**
 * @project: jdk-learnig
 * @description: 通过类名引用静态方法
 * @author: 黄宇辉
 * @date: 8/18/2019-3:36 PM
 * @version: 1.0
 * @website: https://yubuntu0109.github.io/
 */
public class RefStatisMethodByClazzName {

    public int getResult(int x, int y, calculable calculable) {
        return calculable.add(x, y);
    }

    //传统写法
    @Test
    public void testGetResult() {
        int result = getResult(1, 2, new calculable() {
            @Override
            public int add(int x, int y) {
                return Method.add(x, y);
            }
        });
        System.out.println(result);
    }

    //Lambda表达式写法
    @Test
    public void testGetResultWithLambda() {
        int result = getResult(1, 2, (x, y) -> Method.add(x, y));
        System.out.println(result);
    }

    //方法引用写法
    @Test
    public void testGetResultWithMethodRef() {
        int result = getResult(1, 2, Method::add);
        System.out.println(result);
    }
}